package CheckBox;

import javax.swing.*;
import java.awt.*;

public class MyCheckBox extends JPanel {
    public JCheckBox[] box;

    public MyCheckBox(String title,String[] item,int x,int y,JFrame CheckBoxTest){
        JLabel jl = new JLabel(title);
        jl.setBounds(x,y,80,30);
        CheckBoxTest.add(jl);

        this.setBounds(x+100,y,item.length*60,30);
        CheckBoxTest.add(this);

        box = new JCheckBox[item.length];
        for (int i=0;i<item.length;i++){
            box[i] = new JCheckBox(item[i]);
            this.add(box[i]);

            if (i%2==0){
                box[i].setSelected(true);
            }
        }
    }

    public String[] getItem(){
        String s ="";
        for (JCheckBox checkBox: box){
            if (checkBox.isSelected()){
                s += checkBox.getText()+",";
            }
        }
        return s.split(",");
    }


}
